package Client.PokerClient.src;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Listener klasy ServerWindow.
 * @author Artur Smolibowski
 */
public class ServerListener implements ActionListener {
  /**
   * Referencja do klasy glownej.
   */
  private Client client;
  /**
   * Klasa nasluchiwana.
   */
  private ServerWindow serverWindow;
  /**
   * Konstruktor klasy.
   * @param client Referencja do klasy glownej.
   * @param serverWindow Klasa nasluchiwana.
   */
  ServerListener(Client client, ServerWindow serverWindow) {
    this.client=client;
    this.serverWindow=serverWindow;
  }
  /**
   * Metoda zajmujaca sie zdarzeniami wystepujacymi w klasie ServerWindow.
   */
  public void actionPerformed(ActionEvent e) {
    if(e.getSource() == serverWindow.getServerButton()[0]) {
      if(!serverWindow.getServerList().isSelectionEmpty())
        client.getServerController().S_JOIN(serverWindow.getServerList().getSelectedIndex(), serverWindow.getServerList().getSelectedValue());		  
    }
	if(e.getSource() == serverWindow.getServerButton()[1]) {
	  client.CreateGameWindow();
	  client.getMainWindow().setEnabled(false);
	}
	if(e.getSource() == serverWindow.getServerButton()[2]) {
      client.getGameThread().getClientSTaskController().S_REFRESH();
	}
	if(e.getSource() == serverWindow.getServerButton()[3]) {
	  client.getGameThread().getClientSTaskController().S_DISCONNECT();
	  client.getGameThread().finalize();
	  client.getMenuWindow().ChangeWindow();
	}
  }
}
